package cn.edu.hqu.exp.courseselection.web;

import javax.validation.Valid;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.Errors;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;
import cn.edu.hqu.exp.courseselection.domain.PersonInfo;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Controller
@RequestMapping("/personinfo")
@SessionAttributes("personinfo")
public class PersonInfoController {
	
	@ModelAttribute(name = "personinfo")
	public PersonInfo personinfo() {
		return new PersonInfo();
	}
	
	@GetMapping
	public String personInfoForm(Model model) {
		return "personal";
	}
	
	@PostMapping
	public String processPersoninfo(@Valid @ModelAttribute("personinfo") PersonInfo personinfo,Errors errors,Model model) {
		if(errors.hasErrors()) {
			 return "personal";
		 }
		PersonInfo test = (PersonInfo) model.getAttribute("personinfo");
		log.info("个人信息:"+personinfo);
		log.info("个人信息:"+ test);
		return "redirect:/course";
	}
}
